import React from 'react';
import { createForm } from 'rc-form';
import { Button, InputItem, WhiteSpace,WingBlank,List } from 'antd-mobile';
import 'antd-mobile/dist/antd-mobile.css';
import { connect,dispatch } from 'react-redux'
import { hashHistory} from 'react-router';

let userMsg = {};
class ModifyMsg extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            pickerValue: [],
            dpValue: null,
            username:'',
            pwd:null,
            fieldName:'',
            fieldValue:''
        };
    }
    componentDidMount() {
        this.props.changeTitle(`修改${userMsg.fieldName}`);
        this.setState({
            fieldName: userMsg.fieldName,
            fieldValue: userMsg.fieldValue
        });
    }

    componentWillMount(){
        userMsg = this.props.location.state;
    }

    submit = (e) => {
        let value = this.props.form.getFieldsValue();//{fieldValue: "323"}
        if (userMsg.fieldName === '昵称'){
            userMsg.userMsg.nick_name = value.fieldValue;
        }else if (userMsg.fieldName === '移动电话'){
            userMsg.userMsg.mobile_phone = value.fieldValue;
        }else if (userMsg.fieldName === '办公电话'){
            userMsg.userMsg.office_phone = value.fieldValue;
        }else if (userMsg.fieldName === '家用电话'){
            userMsg.userMsg.home_phone = value.fieldValue;
        }else if (userMsg.fieldName === 'QQ'){
            userMsg.userMsg.qq = value.fieldValue;
        }
        hashHistory.push({
            pathname: '/user/details',
            state: userMsg.userMsg

        })
    }


    render() {
        const { getFieldProps } = this.props.form;
        return (<div >
            <List>
                <InputItem
                    {...getFieldProps('fieldValue',
                        {
                            initialValue: this.state.fieldValue,
                        })}
                    type="text">
                    {this.state.fieldName}
                </InputItem>
            </List>
            <WhiteSpace/>
            <WingBlank>
                <Button type="warning" size="large" onClick={this.submit}>确 定</Button><WhiteSpace/>
            </WingBlank>
        </div>);
    }
}

export default createForm()(ModifyMsg);
